package com.wbao.dianniu.test;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yejianjun on 2018/6/6.
 */

public class MyAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> list = new ArrayList<String>();

    public MyAdapter(Context context) {
        mContext = context;
    }

    public void setData(List<String> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if (null == convertView) {
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(android.R.layout.simple_list_item_1, null);
            holder.tv = (TextView) convertView.findViewById(android.R.id.text1);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.tv.setText(list.get(position));
        return convertView;
    }

    class Holder {
        TextView tv;
    }

}
